package thirt.component
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.utils.setTimeout;

	public class TextSprite extends Sprite
	{
		private var _txt:TextField;
		private var _textFormate:TextFormat;
		private var _content:String;
		private var _fontface:String = '微软雅黑';
		private var _color:uint = 0x666666;
		private var _size:int = 15;
		public function TextSprite()
		{
			super();
			init();
		}
		private function init():void{
			_txt = new TextField;
			_txt.type = TextFieldType.INPUT;
			_txt.multiline = true;
			_txt.wordWrap = true;
			//_txt.border = true;
			
			_textFormate = new TextFormat;
			_textFormate.align = TextFormatAlign.CENTER;
			_textFormate.color = 0x666666;
			_textFormate.size = 14;
			_textFormate.font = "微软雅黑";
			
			_txt.defaultTextFormat = _textFormate;
			_txt.autoSize = TextFieldAutoSize.LEFT;
			
			_txt.text = "在这输入文字";
			
			this.addChild(_txt);
			setTimeout(draw,10);
		}
		
		public function draw():void{
			this.graphics.clear();
			this.graphics.beginFill(0xffff00,0);
			this.graphics.drawRect(0,0,_txt.width,_txt.height);
			this.graphics.endFill();
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		public function set text(value:String):void{
			_txt.text = value;
		}
		public function set fontface(value:String):void
		{
			_fontface = value;
			_textFormate.font = value;
			_txt.setTextFormat(_textFormate);
			setTimeout(draw,10);
		}

		public function set color(value:uint):void
		{
			_color = value;
			_textFormate.color = value;
			_txt.setTextFormat(_textFormate);
			setTimeout(draw,10);
		}
		public function set size(value:int):void{
			_size = value;
			_textFormate.size = value;
			_txt.setTextFormat(_textFormate);
			setTimeout(draw,10);
		}
		public function set B(value:Boolean):void{
			_textFormate.bold = value;
			_txt.setTextFormat(_textFormate);
			setTimeout(draw,10);
		}
		public function set I(value:Boolean):void{
			_textFormate.italic = value;
			_txt.setTextFormat(_textFormate);
			setTimeout(draw,10);
		}
		public function get size():int{
			return _size;
		}
		public function set textWidth(value:int):void{
			_txt.width = value;
			setTimeout(draw,10);
		}
		public function set align(value:String):void{
			_textFormate.align = value;
			_txt.setTextFormat(_textFormate);
			setTimeout(draw,10);
		}
		public function removeFouse():void{
			/* if(stage)
				stage.focus = null;  */
		}
		
		public function setAllSelect():void{
			stage.focus = _txt;
			_txt.setSelection(0,_txt.text.length);
		}
		
		public function setFouse():void{
			if(stage)
				stage.focus = _txt;
		}
		
		public function getInfo():Object{
			var obj:Object = new Object;
			obj.text = _txt.text;
			obj.align = _textFormate.align;
			obj.color = _textFormate.color;
			obj.size = _textFormate.size;
			obj.font = _textFormate.font;
			obj.bold = _textFormate.bold;
			obj.italic = _textFormate.italic;
			obj.textWidth = _txt.width;
			return obj;
		}
		
	}
}